package com.ccxe.io;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;


public class FilterKey implements WritableComparable<FilterKey>, Cloneable {

	private int c_stock_no=0;
	private long c_date_time=0;

	public FilterKey() {
	}

	public FilterKey(String[] a){
		this.c_stock_no = Integer.parseInt(a[0]);
		this.c_date_time = Long.parseLong(a[1]);
	}

	
	public FilterKey(String c_stock_no, String c_date_time) {
		this.c_stock_no = Integer.parseInt(c_stock_no);
		this.c_date_time = Long.parseLong(c_date_time);
	}

	public FilterKey(int i ,long l) {
		this.c_stock_no = i;
		this.c_date_time = l;
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(c_stock_no);
		out.writeLong(c_date_time);
	}

	public static FilterKey read(DataInput in) throws IOException {
		FilterKey result = new FilterKey();
		result.readFields(in);
		return result;
	}
	@Override
	public void readFields(DataInput in) throws IOException {
		c_stock_no = in.readInt();
		c_date_time = in.readLong();
	}

	/**
	 * 根据stick_no升序，datatime升序排序
	 */
	@Override
	public int compareTo(FilterKey that) {
		if (this.c_stock_no != that.c_stock_no) {
			if (this.c_stock_no < that.c_stock_no)
				return -1;
			else
				return 1;
		}
		if (this.c_date_time != that.c_date_time) {
			if (this.c_date_time < that.c_date_time)
				return -1;
			else
				return 1;
		}
		return 0;
	}

	@Override
	public String toString() {
		return c_stock_no + "_" + c_date_time;
	}

	/*************************** getters and setters ******************************************/
	public int getC_stock_no() {
		return c_stock_no;
	}

	public void setC_stock_no(String c_stock_no) {
		this.c_stock_no = Integer.parseInt(c_stock_no);
	}
	public void setC_stock_no(int c_stock_no) {
		this.c_stock_no = c_stock_no;
	}

	public long getC_date_time() {
		return c_date_time;
	}

	public void setC_date_time(String c_date_time) {
		this.c_date_time = Long.parseLong(c_date_time);
	}
	public void setC_date_time(long c_date_time) {
		this.c_date_time = c_date_time;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof FilterKey) {
			FilterKey data = (FilterKey) obj;
			return c_stock_no == data.getC_stock_no()
					&& c_date_time == data.getC_date_time();
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}
	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
	
}
